package com.atguigu.gmall.cart.exception.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import sun.util.locale.provider.LocaleServiceProviderPool;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: 86182
 * @Date: 2021/8/21
 * @Time: 1:10
 * @Version:
 */
@Slf4j
@Component
public class CartAsyncUncaghtExceptionHandler implements AsyncUncaughtExceptionHandler {

    @Autowired
    private StringRedisTemplate redisTemplate;

    private static final  String EXCEPTION_KEY = "cart:exception";
    @Override
    public void handleUncaughtException(Throwable ex, Method method, Object... params) {
        //log.error("异步任务出错. 方法: {}, 参数: {}, 异常信息: {}",method.getName(), Arrays.asList(params),ex.getMessage());
        BoundSetOperations<String, String> setOps = this.redisTemplate.boundSetOps(EXCEPTION_KEY);
        setOps.add(params[0].toString());
    }
}
